#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#include "portaudio.h"
#include "rstream.h"

int main(void)
{
	PortAudioInit init;
	recordStream rstream;
	bool gotFreq = 0;
	if(!rstream.open(init))
	{
		fprintf(stderr, "Error opening record stream\n");
		exit(1);
	}
	printf("Recording, control-c to stop\n");
	
	while(1)
	{
		// Wait 100ms between processing.
		Pa_Sleep(100);
		
		float max, avg_abs, bestpeak_freq;
		
		gotFreq = rstream.audioInput(max, avg_abs, bestpeak_freq);
		
		if(gotFreq)
		{
			printf("Freq: %6.1f Hz", bestpeak_freq);
		}
		else
		{
			printf("--");
		}
		printf("\n");
		
		fflush(stdout);
	}
	rstream.close();
	return 0;
}
